package com.awesumgames.testgame;

import android.util.Log;

import com.awesumgames.awesum.AwesumGlobal.Awesum;
import com.awesumgames.awesum.Drawable.TraitFlag;
import com.awesumgames.awesum.controls.Control.Ouya;
import com.awesumgames.awesum.Drawable;
import com.awesumgames.awesum.Game;
import com.awesumgames.awesum.Primitives;
import com.awesumgames.awesum.Scene;
import com.awesumgames.awesum.Vector3;
import com.awesumgames.awesum.Vector4;
import com.bulletphysics.collision.shapes.BoxShape;
import com.bulletphysics.linearmath.Transform;

import tv.ouya.console.api.OuyaController;

public class Paddle extends Drawable {
	public enum Type {NORMAL, REVERSE, HALF_LEFT, HALF_MIDDLE, HALF_RIGHT, MINI};
	private Type _type = Type.NORMAL;
	private Block _tumor;
	
	Paddle(Type type, Vector3 pos) {
		super();
		_type = type;
	}
	
	public void load() {
		//_tumor = new Block(Block.Type.NORMAL, new Vector3(0, .25, 0));
		//add(_tumor);
		//gl.scale.set(2f, .25f, 1f);
		//the bounding box must be fixed because the gl scale is different
		//coll.box.offset.set(0f, gl.scale.y, 0f);
		//coll.box.size.set(gl.scale);
		super.load(TraitFlag.Gl.flag | TraitFlag.Move.flag | TraitFlag.Phys.flag);

		Vector3 dims = new Vector3(1f, .125f, .5f);
		Primitives.buildRect(this, dims, new Vector4(0f, 0f, 1f, 1f), BreakoutLayer.COLL_BLOCK, BreakoutLayer.MASK_BLOCK);
		phys.moveManual = true;
		phys.collShape = new BoxShape(dims);
		phys.init(2.5f, 1f, BreakoutLayer.COLL_BLOCK, BreakoutLayer.MASK_BLOCK);
		phys.receiveCollisions = false;
		phys.body.setMassProps(0f, new Vector3());
	}
	
	public void step() {
		super.step();
		
		int p = 0;
        if (Ouya.stickLMag[p] >= OuyaController.STICK_DEADZONE) {
        	pos.x += .35 * (Ouya.stickLX[p]);
        	pos.x = Awesum.clamp(pos.x, 0f, 8f);
        }
        
        if (Game.accelerometer != null) {
			//Awesum.debug("acc: " + Game.accelerometer[0] + ", " + Game.accelerometer[1] + ", " + Game.accelerometer[2]);
			float v = Math.min(Game.accelerometer.x, 5f) / 10f;
			float absV = Math.abs(v);
			if (absV >= .05) {
				pos.x += Math.copySign(Math.max(absV, .1), v);// * 1.2;
				pos.x = Awesum.clamp(pos.x, 1f, 9f);
			}
		}
	}
}
